const getters = {
  avatar: state => state.user.avatar || '/package-guest/static/me/avatar.png',
  nickname: state => state.user.nickname || '微信用户',
  mobile: state => state.user.mobile,
  userId: state => state.user.userId,
  /** 数据字典 */
  dict_datas: state => state.dict.dictDatas,
  /** 办公菜单 */
  menus: state => state.menu.menus,
  /** 办公菜单叶子节点 proDefId -> 菜单对象 映射 map */
  menuLeafMap: (state) => {
    const map = {}

    function traverse(arr) {
      for (const menu of arr) {
        if (menu.children && menu.children.length > 0) {
          traverse(menu.children)
          continue
        }

        if (menu.procdefId) {
          map[menu.procdefId] = menu
        }
      }
    }

    traverse(state.menu.menus)

    return map
  },
}

export default getters
